import React, { Component } from 'react'

export default class setState extends Component {
    state = { count: 0 }
    add = () => {
        const { count } = this.state
        // 对象式
        // this.setState({ count: count + 1 })
        this.setState({ count: count + 1 },()=>{
            console.log('count-回调',this.state.count);
        })
        console.log('count-外层',count);

        // 函数式
        // this.setState((state, props) => {
        //     console.log(state, props);
        //     return { count: state.count + 1 }
        // })
    }
    render() {
        return (
            <div>
                <h1>当前求和为：{this.state.count}</h1>
                <button onClick={this.add}>点击加一</button>
            </div>
        )
    }
}
